package org.example.dao.address;

import org.apache.ibatis.annotations.*;
import org.example.entity.Address;

import java.util.List;

@Mapper
public interface AddressMapper {


    @Insert("insert into user_address( open_id, username, phone, area, address, status) " +
            "values (#{openId},#{username},#{phone},#{area},#{address},#{status})")
    boolean addAddress(Address address);

    @Delete("delete from user_address where address_id = #{addressId}")
    boolean deleteAddress(Integer addressId);

    @Update("update user_address set username =#{username},area=#{area}," +
            "address = #{address},status=#{status} where address_id = #{addressId}")
    boolean updateAddress(Address address);

    @Select("select * from user_address where open_id = #{openId} order by status desc")
    List<Address> list(String openId);

    @Update("update user_address set status='0' where open_id = #{open_Id}")
    void setAddressStatusToZero(String openId);

    @Select("select * from user_address where open_id = #{openId} and status = '1' order by status desc")
    Address getDefaultAddress(String openId);
}
